﻿<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="Column" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  
  <alias>
    <typeAlias alias="Column" type="Lyh.Dbdg.Model.Column"/>
  </alias>
  
  <resultMaps>
    <resultMap id="ColumnResult" class="Column">
      <result property="Order" column="Order"/>
      <result property="Name" column="Name"/>
      <result property="DbType" column="DbType"/>
      <result property="Length" column="Length"/>
      <result property="Precision" column="Precision"/>
      <result property="Scale" column="Scale"/>
      <result property="IsNullable" column="IsNullable"/>
      <result property="DefaultValue" column="DefaultValue"/>
      <result property="Description" column="Description"/>
      <result property="IsPrimaryKey" column="IsPrimaryKey"/>
      <result property="IsIdentity" column="IsIdentity"/>
    </resultMap>
  </resultMaps>
  
  <cacheModels>
    <cacheModel id="ColumnCache" implementation="LRU">
      <flushInterval hours="24"/>
      <property name="CacheSize" value="1000"/>
    </cacheModel>
  </cacheModels>
  
  <statements>
    <select id="GetList" resultMap="ColumnResult" cacheModel="ColumnCache">
      SELECT DISTINCT ORDINAL_POSITION 'Order',
      COLUMN_NAME 'Name',
      DATA_TYPE DbType,
      IFNULL(CHARACTER_MAXIMUM_LENGTH,0) Length,
      IFNULL(NUMERIC_PRECISION,0) 'Precision',
      IFNULL(NUMERIC_SCALE,0) Scale,
      CASE WHEN IS_NULLABLE = 'NO' THEN 0 ELSE 1 END  IsNullable,
      COLUMN_DEFAULT DefaultValue,
      COLUMN_COMMENT Description,
      CASE WHEN COLUMN_KEY = 'PRI' THEN 1 ELSE 0 END IsPrimaryKey,
      0 IsIdentity
      FROM information_schema.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = #value#
    </select>
  </statements>
  
</sqlMap>